System and method for supporting dynamic thread pool sizing in a distributed data grid

ABSTRACT

A system and method supports dynamic thread pool sizing suitable for use in multi-threaded processing environment such as a distributed data grid. Dynamic thread pool resizing utilizes measurements of thread pool throughput and worker thread utilization in combination with analysis of the efficacy of prior thread pool resizing actions to determine whether to add or remove worker threads from a thread pool in a current resizing action. Furthermore, the dynamic thread pool resizing system and method can accelerate or decelerate the iterative resizing analysis and the rate of worker thread addition and removal depending on the needs of the system. Optimizations are incorporated to prevent settling on a local maximum throughput. The dynamic thread pool sizing/resizing system and method thereby provides rapid and responsive adjustment of thread pool size in response to changes in work load and processor availability.

CLAIM OF PRIORITY

This application claims priority to U.S. Provisional Patent ApplicationNo. 62/055,476, entitled “SYSTEM AND METHOD FOR SUPPORTING DYNAMICTHREAD POOL SIZING IN A DISTRIBUTED DATA GRID” filed Sep. 25, 2014, andU.S. Provisional Patent Application No. 62/055,477, entitled “SYSTEM ANDMETHOD FOR SUPPORTING A SCALABLE THREAD POOL IN A DISTRIBUTED DATA GRID”filed Sep. 25, 2014 which applications are incorporated herein byreference.

CROSS REFERENCE TO RELATED APPLICATIONS

This application is related to the following patent application, whichis hereby incorporated by reference in its entirety: U.S. PatentApplication titled “SYSTEM AND METHOD FOR SUPPORTING A SCALABLE THREADPOOL IN A DISTRIBUTED DATA GRID”, application Ser. No. ______, filed______ (ORACL-05568US1).

COPYRIGHT NOTICE

A portion of the disclosure of this patent document contains materialwhich is subject to copyright protection. The copyright owner has noobjection to the facsimile reproduction by anyone of the patent documentor the patent disclosure, as it appears in the Patent and TrademarkOffice patent file or records, but otherwise reserves all copyrightrights whatsoever.

FIELD OF INVENTION

The present invention is generally related to computer systems, and isparticularly related to a distributed data grid.

SUMMARY

Described herein are systems and methods that can support thread poolsizing and resizing in a distributed data grid. As described in thedescription of a distributed data grid which follows, services providedby a node of a distributed data grid typically uses one service threadto provide the specific functionality of the service. Some servicesoptionally support a thread pool of worker threads that can beconfigured to provide the service thread with additional processingresources. The present disclosure describes a scalable thread pool ofworker threads that can be configured to provide the service thread withadditional processing resources and a system and method for dynamicresizing of the scalable thread pool. The dynamic thread pool sizing andresizing system and method described herein is also applicable in a widevariety of other multi-threaded processing environments.

In embodiments, the present disclosure describes a system and methodwhich support dynamic thread pool sizing suitable for use inmulti-threaded processing environment such as a distributed data grid.Dynamic thread pool resizing can be performed, for example, in ascalable thread pool associated with a service thread in the distributeddata grid. Dynamic thread pool resizing utilizes measurements of threadpool throughput and worker thread utilization in combination withanalysis of the efficacy of prior thread pool resizing actions todetermine whether to add or remove worker threads from a thread pool ina current resizing action. Furthermore, the dynamic thread pool resizingsystem and method can accelerate or decelerate the resizing analysisand, thus, the rate of worker thread addition and removal depending onthe needs of the system. Optimizations are incorporated to preventsettling on a local maximum throughput. The dynamic thread pool resizingsystem and method thereby provides rapid and responsive adjustment ofthread pool size in response to changes in work load and processoravailability.

In embodiments the present disclosure describes systems and methodswhich that can support dynamic thread pool sizing in a distributed datagrid. The system can measure a total throughput of a thread pool for aperiod. Then, the system can determine a change of the total throughputof the thread pool from a last period, and can resize the thread pool bya random amount, if one or more criteria are satisfied. Furthermore, thesystem can determine a length for a next period based on how effective aresizing of the thread pool for the last period is.

In particular embodiments, the present disclosure describes a method,system, or non-transitory medium for supporting dynamic thread poolresizing of a thread pool comprising a plurality of worker threads in amulti-threaded processing system. The method, system, and non-transitorymedium each support dynamic thread pool resizing of a thread pool byperforming a resizing job. The resizing job includes measuring athroughput (T.now) of the thread pool in a current period andcalculating a change in throughput of the thread pool (T.delta) fromT.now and a throughput of the thread pool (T.last) measured in aprevious period. The resizing job further comprises performing aresizing action which comprises one of causing one or more workerthreads to be added the thread pool, causing one or more worker threadsto be removed from the thread pool, and causing no change to the threadpool. The resizing job further comprises calculating a duration for thenext period based on an efficacy, as indicated by T.delta, of a priorresizing action performed after the previous period then scheduling anext resizing job to be performed after expiration of the next period.

These and other objects and advantages of the present invention willbecome apparent to those skilled in the art from the followingdescription of the various embodiments, when read in light of theaccompanying drawings.

BRIEF DESCRIPTION OF THE FIGURES

FIG. 1 illustrates a distributed data grid, in accordance with anembodiment of the invention.

FIG. 2 illustrates a scalable thread pool system, in accordance with anembodiment of the invention.

FIGS. 3A and 3B illustrate a scalable thread pool system and method inaccordance with an embodiment of the invention.

FIG. 4A illustrates a method for adding worker threads to the scalablethread pool system of FIGS. 2, 3A, and 3B, in accordance with anembodiment of the invention.

FIG. 4B illustrates a method for removing worker threads from thescalable thread pool system of FIGS. 2, 3A, and 3B, in accordance withan embodiment of the invention.

FIG. 5 illustrates a method for dynamic sizing of a scalable threadpool, in accordance with an embodiment of the invention.

FIG. 6 illustrates a method for dynamic sizing of a scalable threadpool, in accordance with an embodiment of the invention.

FIG. 7 illustrates implementation of a scalable thread pool and a systemfor dynamic resizing of a scalable thread pool in a distributed datagrid, in accordance with an embodiment of the invention.

DETAILED DESCRIPTION

Described herein are systems and methods that can support dynamic threadpool sizing in a distributed data grid. As described in the descriptionof a distributed data grid which follows, services provided by a node ofa distributed data grid typically uses one service thread to provide thespecific functionality of the service. Some services optionally supporta thread pool of worker threads that can be configured to provide theservice thread with additional processing resources. The presentdisclosure describes a scalable thread pool of worker threads that canbe configured to provide the service thread with additional processingresources and a system and method for dynamic resizing of the scalablethread pool. The system and method for dynamic thread pool sizingdescribed herein have particular utility in the distributed data griddescribed below with respect to FIG. 1 and scalable thread pooldescribed below with respect to FIGS. 2, 3A, 3B, 4A, and 4B. Dynamicthread pool sizing/resizing as disclosed herein may also be applied inwide variety of alternative thread pool systems and other multi-threadedprocessing environments and applications.

In the following description, the invention will be illustrated by wayof example and not by way of limitation in the figures of theaccompanying drawings. References to various embodiments in thisdisclosure are not necessarily to the same embodiment, and suchreferences mean at least one. While specific implementations arediscussed, it is understood that this is provided for illustrativepurposes only. A person skilled in the relevant art will recognize thatother components and configurations may be used without departing fromthe scope and spirit of the invention.

Furthermore, in certain instances, numerous specific details will be setforth to provide a thorough description of the invention. However, itwill be apparent to those skilled in the art that the invention may bepracticed without these specific details. In other instances, well-knownfeatures have not been described in as much detail so as not to obscurethe invention.

The present invention is described with the aid of functional buildingblocks illustrating the performance of specified functions andrelationships thereof. The boundaries of these functional buildingblocks have often been arbitrarily defined herein for the convenience ofthe description. Thus functions shown to be performed by the sameelements may in alternative embodiments be performed by differentelements. And functions shown to be performed in separate elements mayinstead be combined into one element. Alternate boundaries can bedefined so long as the specified functions and relationships thereof areappropriately performed. Any such alternate boundaries are thus withinthe scope and spirit of the invention.

Common reference numerals are used to indicate like elements throughoutthe drawings and detailed description; therefore, reference numeralsused in a figure may or may not be referenced in the detaileddescription specific to such figure if the element is describedelsewhere. The first digit in a three digit reference numeral indicatesthe series of figures in which the element first appears.

Distributed Data Grid

A distributed data grid is a system in which a collection of computerservers work together in one or more clusters to manage information andrelated operations, such as computations, within a distributed orclustered environment. A distributed data grid can be used to manageapplication objects and data that are shared across the servers. Adistributed data grid provides low response time, high throughput,predictable scalability, continuous availability and informationreliability. As a result of these capabilities, a distributed data gridis well suited for use in computational intensive, stateful middle-tierapplications. In particular examples, distributed data grids, such ase.g., the Oracle® Coherence data grid, store information in-memory toachieve higher performance, and employ redundancy in keeping copies ofthat information synchronized across multiple servers, thus ensuringresiliency of the system and continued availability of the data in theevent of failure of a server.

In the following description, an Oracle® Coherence data grid having apartitioned cache is described. However, one of ordinary skill in theart will understand that the present invention, described for example inthe summary above, can be applied to any distributed data grid known inthe art without departing from the scope of the invention. Moreover,although numerous specific details of an Oracle® Coherence distributeddata grid are described to provide a thorough description of theinvention, it will be apparent to those skilled in the art that theinvention may be practiced in a distributed data grid without thesespecific details. Thus, a particular implementation of a distributeddata grid embodying the present invention can, in some embodiments,exclude certain features, and/or include different, or modified featuresthan those of the distributed data grid described below, withoutdeparting from the scope of the invention.

FIG. 1 illustrates and example of a distributed data grid 100 whichstores data and provides data access to clients 150. A “data gridcluster”, or “distributed data grid”, is a system comprising a pluralityof computer servers (e.g., 120 a, 120 b, 120 c, and 120 d) which worktogether in one or more cluster (e.g., 100 a, 100 b, 100 c) to store andmanage information and related operations, such as computations, withina distributed or clustered environment. While distributed data grid 100is illustrated as comprising four servers 120 a, 120 b, 120 c, 120 d,with five data nodes 130 a, 130 b, 130 c, 130 d, and 130 e in a cluster100 a, the distributed data grid 100 may comprise any number of clustersand any number of servers and/or nodes in each cluster. The distributeddata grid can store the information in-memory to achieve higherperformance, and employ redundancy in keeping copies of that informationsynchronized across multiple servers, thus ensuring resiliency of thesystem and continued availability of the data in the event of serverfailure. In an embodiment, the distributed data grid 100 implements thepresent invention, described for example in the summary above and thedetailed description below.

As illustrated in FIG. 1, a distributed data grid provides data storageand management capabilities by distributing data over a number ofservers (e.g., 120 a, 120 b, 120 c, and 120 d) working together. Eachserver of the data grid cluster may be a conventional computer systemsuch as, for example, a “commodity x86” server hardware platform withone to two processor sockets and two to four CPU cores per processorsocket. Each server (e.g., 120 a, 120 b, 120 c, and 120 d) is configuredwith one or more CPU, Network Interface Card (NIC), and memoryincluding, for example, a minimum of 4 GB of RAM up to 64 GB of RAM ormore. Server 120 a is illustrated as having CPU 122 a, Memory 124 a andNIC 126 a (these elements are also present but not shown in the otherServers 120 b, 120 c, 120 d). Optionally each server may also beprovided with flash memory—e.g. SSD 128 a—to provide spillover storagecapacity. When provided the SSD capacity is preferably ten times thesize of the RAM. The servers (e.g., 120 a, 120 b, 120 c, 120 d) in adata grid cluster 100 a are connected using high bandwidth NICs (e.g.,PCI-X or PCIe) to a high-performance network switch 120 (for example,gigabit Ethernet or better).

A cluster 100 a preferably contains a minimum of four physical serversto avoid the possibility of data loss during a failure, but a typicalinstallation has many more servers Failover and failback are moreefficient the more servers that are present in each cluster and theimpact of a server failure on a cluster is lessened. To minimizecommunication time between servers, each data grid cluster is ideallyconfined to a single switch 102 which provides single hop communicationbetween servers. A cluster may thus be limited by the number of ports onthe switch 102. A typical cluster will therefore include between 4 and96 physical servers.

In most Wide Area Network (WAN) configurations of a distributed datagrid 100, each data center in the WAN has independent, butinterconnected, data grid clusters (e.g., 100 a, 100 b, and 100 c). AWAN may, for example, include many more clusters than shown in FIG. 1.Additionally, by using interconnected but independent clusters (e.g.,100 a, 100 b, 100 c) and/or locating interconnected, but independent,clusters in data centers that are remote from one another, thedistributed data grid can secure data and service to clients 150 againstsimultaneous loss of all servers in one cluster caused by a naturaldisaster, fire, flooding, extended power loss and the like. Clustersmaintained throughout the enterprise and across geographies constitutean automatic ‘backup store’ and high availability service for enterprisedata.

One or more nodes (e.g., 130 a, 130 b, 130 c, 130 d and 130 e) operateon each server (e.g., 120 a, 120 b, 120 c, 120 d) of a cluster 100 a. Ina distributed data grid the nodes may be for example, softwareapplications, virtual machines, or the like and the servers may comprisean operating system, hypervisor or the like (not shown) on which thenode operates. In an Oracle® Coherence data grid, each node is Javavirtual machine (JVM). A number of JVM/nodes may be provided on eachserver depending on the CPU processing power and memory available on theserver. JVM/nodes may be added, started, stopped, and deleted asrequired by the distributed data grid. JVMs that run Oracle® Coherenceautomatically join and cluster when started. JVM/nodes that join acluster are called cluster members or cluster nodes.

In an Oracle® Coherence data grid cluster members communicate usingTangosol Cluster Management Protocol (TCMP). TCMP is an IP-basedprotocol that is used to discover cluster members, manage the cluster,provision services, and transmit data between cluster members. The TCMPprotocol provides fully reliable, in-order delivery of all messages.Since the underlying UDP/IP protocol does not provide for eitherreliable or in-order delivery, TCMP uses a queued, fully asynchronousACK and NACK-based mechanism for reliable delivery of messages, withunique integral identity for guaranteed ordering of messages in queuesassociated with the JVMs operating on a server. The TCMP protocolrequires only three UDP/IP sockets (one multicast, two unicast) and sixthreads per JVM/node, regardless of the cluster size.

The functionality of a data grid cluster is based on services providedby cluster nodes. Each service provided by a cluster node has a specificfunction. Each cluster node can participate in (be a member of) a numberof cluster services, both in terms of providing and consuming thecluster services. Some cluster services are provided by all nodes in thecluster whereas other services are provided by only one or only some ofthe nodes in a cluster. Each service has a service name that uniquelyidentifies the service within the data grid cluster, and a service type,which defines what the service can do. There may be multiple namedinstances of each service type provided by nodes in the data gridcluster (other than the root cluster service). All services preferablyprovide failover and failback without any data loss.

Each service instance provided by a cluster node typically uses oneservice thread to provide the specific functionality of the service. Forexample, a distributed cache service provided by a node is provided bysingle service thread of the node. When the schema definition for thedistributed cache is parsed in the JVM/node, a service thread isinstantiated with the name specified in the schema. This service threadmanages the data in the cache created using the schema definition. Someservices optionally support a thread pool of worker threads that can beconfigured to provide the service thread with additional processingresources. The service thread cooperates with the worker threads in thethread pool to provide the specific functionality of the service.

In an Oracle® Coherence data grid, the cluster service (e.g., 136 a, 136b, 136 c, 136 d, 136 e) keeps track of the membership and services inthe cluster. Each cluster node always has exactly one service of thistype running. The cluster service is automatically started to enable acluster node to join the cluster. The cluster service is responsible forthe detection of other cluster nodes, for detecting the failure (death)of a cluster node, and for registering the availability of otherservices in the cluster. The proxy service (e.g., 138 c) allowsconnections (e.g. using TCP) from clients that run outside the cluster.The invocation Service (e.g., 134 d) allows application code to invokeagents to perform operations on any node in the cluster, or any group ofnodes, or across the entire cluster. Although shown on only one nodeeach, the invocation service and proxy service can be configured on anynumber up to all of the nodes of the distributed data grid.

In an Oracle® Coherence data grid, the distributed cache service (e.g.,132 a, 132 b, 132 c, 132 d, 132 e) is the service which provides fordata storage in the distributed data grid and is operative on all nodesof the cluster that read/write/store cache data, even if the node isstorage disabled. The distributed cache service allows cluster nodes todistribute (partition) data across the cluster 100 a so that each pieceof data in the cache is managed primarily (held) by only one clusternode. The distributed cache service handles storage operation requestssuch as put, get, etc. The distributed cache service manages distributedcaches (e.g., 140 a, 140 b, 140 c, 140 d, 140 e) defined in adistributed schema definition and partitioned among the nodes of acluster.

A partition is the basic unit of managed data in the distributed datagrid and stored in the distributed caches (e.g., 140 a, 140 b, 140 c,140 d, and 140 e). The data is logically divided into primary partitions(e.g., 142 a, 142 b, 142 c, 142 d, and 142 e), that are distributedacross multiple cluster nodes such that exactly one node in the clusteris responsible for each piece of data in the cache. Each cache (e.g.,140 a, 140 b, 140 c, 140 d, and 140 e) can hold a number of partitions.Each partition (e.g., 142 a, 142 b, 142 c, 142 d, 142 e) may hold onedatum or it may hold many. A partition can be migrated from the cache ofone node to the cache of another node when necessary or desirable. Forexample, when nodes are added to the cluster, the partitions aremigrated so that they are distributed among the available nodesincluding newly added nodes. In a non-replicated distributed data gridthere is only one active copy of each partition (the primary partition).However, there is typically also one or more replica/backup copy of eachpartition (stored on a different server) which is used for failover.Because the data is spread out in partition distributed among theservers of the cluster, the responsibility for managing and providingaccess to the data is automatically load-balanced across the cluster.

The distributed cache service can be configured so that each piece ofdata is backed up by one or more other cluster nodes to support failoverwithout any data loss. For example, as shown in FIG. 1, each partitionis stored in a primary partition (e.g., dark shaded squares 142 a, 142b, 142 c, 142 d, and 142 e) and one or more synchronized backup copy ofthe partition (e.g., light shaded squares 144 a, 144 b, 144 c, 144 d,and 144 e). The backup copy of each partition is stored on a separateserver/node than the primary partition with which it is synchronized.Failover of a distributed cache service on a node involves promoting thebackup copy of the partition to be the primary partition. When aserver/node fails, all remaining cluster nodes determine what backuppartitions they hold for primary partitions on failed node. The clusternodes then promote the backup partitions to primary partitions onwhatever cluster node they are held (new backup partitions are thencreated).

A distributed cache is a collection of data objects. Each dataobject/datum can be, for example, the equivalent of a row of a databasetable. Each datum is associated with a unique key which identifies thedatum. Each partition (e.g., 142 a, 142 b, 142 c, 142 d, 142 e) may holdone datum or it may hold many and the partitions are distributed amongall the nodes of the cluster. In an Oracle® Coherence data grid each keyand each datum is stored as a data object serialized in an efficientuncompressed binary encoding called Portable Object Format (POF).

In order to find a particular datum, each node has a map, for example ahash map, which maps keys to partitions. The map is known to all nodesin the cluster and is synchronized and updated across all nodes of thecluster. Each partition has a backing map which maps each key associatedwith the partition to the corresponding datum stored in the partition.An operation associated with a particular key/datum can be received froma client at any node in the distributed data grid. When the nodereceives the operation, the node can provide direct access to thevalue/object associated with the key, if the key is associated with aprimary partition on the receiving node. If the key is not associatedwith a primary partition on the receiving node, the node can direct theoperation directly to the node holding the primary partition associatedwith the key (in one hop). Thus, using the hash map and the partitionmaps, each node can provide direct or one-hop access to every datumcorresponding to every key in the distributed cache.

In some applications, data in the distributed cache is initiallypopulated from a database 110 comprising data 112. The data 112 indatabase 110 is serialized, partitioned and distributed among the nodesof the distributed data grid. Distributed data grid 100 stores dataobjects created from data 112 from database 110 in partitions in thememory of servers 120 a, 120 b, 120 c, 120 d such that clients 150and/or applications in data grid 100 can access those data objectsdirectly from memory. Reading from and writing to the data objects inthe distributed data grid 100 is much faster and allows moresimultaneous connections than could be achieved using the database 110directly. In-memory replication of data and guaranteed data consistencymake the distributed data grid suitable for managing transactions inmemory until they are persisted to an external data source such asdatabase 110 for archiving and reporting. If changes are made to thedata objects in memory the changes are synchronized between primary andbackup partitions and may subsequently be written back to database 110using asynchronous writes (write behind) to avoid bottlenecks.

Although the data is spread out across cluster nodes, a client 150 canconnect to any cluster node and retrieve any datum. This is calledlocation transparency, which means that the developer does not have tocode based on the topology of the cache. In some embodiments, a clientmight connect to a particular service e.g., a proxy service on aparticular node. In other embodiments, a connection pool or loadbalancer may be used to direct a client to a particular node and ensurethat client connections are distributed over some or all the data nodes.However connected, a receiving node in the distributed data gridreceives tasks from a client 150, and each task is associated with aparticular datum, and must therefore be handled by a particular node.Whichever node receives a task (e.g. a call directed to the cacheservice) for a particular datum identifies the partition in which thedatum is stored and the node responsible for that partition, thereceiving node, then directs the task to the node holding the requestedpartition for example by making a remote cache call. Since each piece ofdata is managed by only one cluster node, an access over the network isonly a “single hop” operation. This type of access is extremelyscalable, since it can use point-to-point communication and thus takeoptimal advantage of a switched fabric network such as InfiniBand.

Similarly, a cache update operation can use the same single-hoppoint-to-point approach with the data being sent both to the node withthe primary partition and the node with the backup copy of thepartition. Modifications to the cache are not considered complete untilall backups have acknowledged receipt, which guarantees that dataconsistency is maintained, and that no data is lost if a cluster nodewere to unexpectedly fail during a write operation. The distributedcache service also allows certain cluster nodes to be configured tostore data, and others to be configured to not store data.

In some embodiments, a distributed data grid is optionally configuredwith an elastic data feature which makes use of solid state devices(e.g. SSD 128 a), most typically flash drives, to provide spillovercapacity for a cache. Using the elastic data feature a cache isspecified to use a backing map based on a RAM or DISK journal. Journalsprovide a mechanism for storing object state changes. Each datum/valueis recorded with reference to a specific key and in-memory trees areused to store a pointer to the datum (a tiny datum/value may be storeddirectly in the tree). This allows some values (data) to be stored insolid state devices (e.g. SSD 128 a) while having the index/memory treestored in memory (e.g. RAM 124 a). The elastic data feature allows thedistributed data grid to support larger amounts of data per node withlittle loss in performance compared to completely RAM-based solutions.

A distributed data grid such as the Oracle® Coherence data griddescribed above can improve system performance by solving data operationlatency problems and by caching and processing data in real time.Applications cache data in the data grid, avoiding expensive requests toback-end data sources. The shared data cache provides a single,consistent view of cached data. Reading from the cache is faster thanquerying back-end data sources and scales naturally with the applicationtier. In memory performance alleviates bottlenecks and reduces datacontention, improving application responsiveness. Parallel query andcomputation is supported to improve performance for data-basedcalculations. The distributed data grid is fault-tolerant, providing fordata reliability, accuracy, consistency, high availability, and disasterrecovery. The distributed data grid enables applications to scalelinearly and dynamically for predictable cost and improved resourceutilization. For many applications, a distributed data grid offers avaluable shared data source solution.

In embodiments, the distributed data grid 100 implements one or morescalable thread pool system and method as described, for example, belowand illustrated in FIGS. 2, 3A, 3B, 4A, and 4B. In embodiments of thepresent invention, distributed data grid 100 implements one or moresystem and method for dynamic resizing of a scalable thread pool asdescribed below and illustrated in FIGS. 5 and 6. In particularembodiments, the scalable thread pool system and method and/or thesystem and method for dynamic resizing of a scalable thread pool may beimplemented with respect to one or more service thread operating onnodes of the distributed data grid 100, including for example, the cacheservice thread, and proxy service thread.

Thread Pools

Described herein are systems and methods that can support dynamic threadpool sizing in a distributed data grid. As described in the descriptionof a distributed data grid provided above, services provided by a nodeof a distributed data grid typically use one service thread to providethe specific functionality of the service. Some services optionallysupport a thread pool of worker threads which can be configured toprovide the service thread with additional processing resources. Thepresent disclosure describes a scalable thread pool of worker threadsthat can be configured to provide the service thread with additionalprocessing resources and a system and method for dynamic sizing/resizingof the scalable thread pool.

A distributed data grid, as described above, is configured to processvery large numbers of short tasks received from clients. For example,the service thread of a distributed cache service is configured toprocess very large numbers of storage operation requests such as put,get, etc. received from applications or other nodes the network. Theprocessing of each storage operation is short-lived, however, the numberof storage operations is very large. In order to efficiently process thevery large number of short-lived operations, a service thread such asthe service thread for the cache service can utilize a thread pool ofworker threads.

If the number of tasks is very large, such as in a distributed datagrid, then creating a thread for each task is impractical. Moreover ifthe size of the tasks is small, the overhead associated with creatingand destroying a thread is more significant relative to the actual workperformed. In a thread pool, worker threads are recycled instead ofcreated on demand as tasks are received. Using a thread pool of workerthreads is advantageous compared to creating new worker threads for eachtask because a thread pool allows reusing threads for multipleoperations, thus the overhead associated with thread-creation andremoval is spread over many operations. Reduced overhead for threadcreation and destruction may result in better performance and bettersystem stability. As an additional advantage, processing of a task isnot delayed by the need to create a new thread to process it. Typically,there are many more tasks than threads. As soon as a thread completesits task, it will request the next task from the queue until all taskshave been completed. The thread can then terminate, or sleep, untilthere are new tasks available.

In general, the optimum size for a thread pool depends on the number ofprocessor cores available to a process and the nature and volume of thework. Creating and destroying a thread and its associated resources isan expensive process in terms of time. However, keeping an excessivenumber of threads alive will also waste memory, and context-switchingbetween the runnable threads also damages performance. Having too manythreads in a thread pool is wasteful of system resources as many of thethreads will be idle. Having two few threads in a thread pool causesdelay as tasks are required to wait until a thread becomes available. Itis desirable to select a thread pool size which minimizes both waste ofresources due to idle threads and delays caused by too few threads.Selecting an optimum thread pool size thus depends upon systemperformance and workload. Thus, the number of threads used in a threadpool is a parameter that can be tuned to provide the best performance.

The number of threads in a thread pool can be dynamically changed basedon workload. The method used to determine when to create or destroythreads will have an impact on the overall performance. If too manythreads are created, resources are wasted and time is wasted creatingunused threads. If too many threads are destroyed time/resources will bewasted creating new threads when required. Creating threads too slowlymight result in long wait times. Destroying idle threads too slowly maystarve other processes of resources. Thus, the number of threads in athread pool and the mechanism for determining when and how fast to addthreads to the thread pool can significantly affect performance of thethread pool, the service thread using the thread pool, and other threadssharing resources of the computer system.

In a distributed data grid, the workload may change significantly fromservice thread to service thread and over time with respect to eachservice thread. Adding complexity is the fact that in a distributed datagrid, a number of cache services for different named caches may operatein the same node simultaneously. Furthermore multiple nodes withmultiple different service threads may operate on the same servertherefore sharing the processor resources. The utilization of thesevarious service threads may also change over time. Thus, in adistributed data grid the optimum size for a thread pool can varydramatically, based not only on the work presented to the service threadassociated with the thread pool, but also based on what work isconcurrently being presented to other service threads on the sameserver.

When implementing a thread pool, thread-safety has to be taken intoaccount. Tasks related to the same resource must be performed in order.If multiple threads pick up tasks related to the same resource only oneof those thread will be able to proceed at a time. This is adisadvantageous because it negates the purpose of multiplethreads—namely having multiple threads operating in parallel. Thereforetechniques are required to ensure first-in-first-out FIFO ordering oftasks and prevent thread blocking/serialization—one common solution is asingle producer multiple consumer queue—however the use of such a queueleads to its own sources of contention as described below. With aconventional queue data structure the multiple consumer worker threadscontend with each other for access to the queue. Only one worker threadcan read from the queue at a time. Increasing the number of workerthreads increases the contention on the queue. Thus, the single producermultiple consumer queue does not readily scale to large numbers ofworker threads. Thus, a thread pool using a simple queue to communicatewith a service thread is not scalable. It is therefore desirable toprovide a data structure for providing work to worker threads thatreduces and/or eliminates contention while allowing scaling of thethread pool while maintaining thread safety.

In view of the problems with conventional thread pools, and thread poolsizing methods, the present disclosure describes a scalable thread poolof worker threads that can be configured to provide the service threadwith additional processing resources and a system and a method fordynamic resizing of a scalable thread pool. In particular, the presentdisclosure describes a single producer multiple consumer dynamicallyscalable thread pool that exhibits high performance on multi-coresystems and is suitable for providing a service thread of a distributeddata grid with additional worker threads when required thereby improvingperformance of the distributed data grid. Furthermore, the presentdisclosure describes a data structure for providing work to workerthreads that reduces and/or eliminates contention while allowing scalingof the thread pool. Furthermore, the present discloses mechanism forchanging the number of threads in a thread pool dynamically selecting athread pool size that optimizes performance and allowing the thread poolsize to change rapidly in response to throughput changes.

Scalable Thread Pool System

FIG. 2 shows an overview of a scalable thread pool system suitable foruse in a distributed data grid. As shown in FIG. 2, a service thread 201in the distributed data grid 200 can receive one or more messages, e.g.messages 211-213. Furthermore, the service thread 201 can either processthe messages 211-213, or provide the messages 211-213 to a scalablethread pool 202, which contains one or more worker threads 221-223. Thesystem can use an association pile 210 to hold one or more elements(e.g. the messages 211-213). Furthermore, the system allows multiplethreads (e.g. the worker threads 221-223) to poll elements from theassociation pile 210 in parallel. Additionally, the system can preventan element, which is held in the association pile 210 and has anassociation with a previously polled element, from being polled untilthe previously polled associated elements has been released.

An association pile, such as association pile 210, is a data structurethat holds elements in a loosely ordered way with a queue-like contract.The association pile respects the possibility that some elements can beassociated with one another by way of an associated key. Elementsassociated with the same key should maintain first-in-first-out (FIFO)ordering, but may be re-ordered with respect to elements associated withdifferent keys. The key may be, for example, the unique key whichidentifies a datum in the distributed data grid as described above. Onlyone thread can operate on a particular datum at a time and operationsperformed on a particular datum should be performed in the order theyare received. Accordingly an association pile can, for an example,maintain first-in-first-out (FIFO) ordering of operations performed on asame datum associated with a same unique key.

Elements can be added to and removed from an association pile. Elementsare added to the association pile by a calling thread. Elements areremoved from an association pile by a worker thread. Removing an elementis performed in two steps: first an available element is removed by aworker thread “polling” the association pile; second when the workerthread is finished with the element it is “released” from theassociation pile. The association pile assumes that polled-butnot-yet-released elements are being processed in parallel on multiplethreads and therefore prevents polling of any element associated withthe same key as a polled-but not-yet-released element.

FIGS. 3A and 3B show an example of a scalable thread pool. As shown inFIGS. 3A and 3B, a service thread 300 is associated with a scalablethread pool 300. Thread pool 300 has of a fixed number (CPU count) ofwork slots 310. Four work slots 310 a, 310 b, 310 c, and 310 d areshown. Each work slot has a thread gate which can either be open orclosed. When the thread gate is open a thread can enter and exit thegate. When a thread has entered a gate, the gate cannot be closed. Whenthe thread gate is closed threads cannot enter the gate.

When work is added to the thread pool by the service thread, the work isdistributed across the work slots. The service thread adds the work tothe slot 310 a, 310 b, 310 c, or 310 d with the smallest backlog (i.e.the slot with the smallest association pile) with some randomness.However all work associated with the same key is added to the same slotin order to preserve ordering of associated work. When work is added toa work slot of a thread pool, the calling thread enters the thread gateof the work slot and adds the work to an association pile as describedbelow.

A thread pool's fixed number (CPU count) of work slots are linked to oneor more worker threads by way of one or more association pile. Thethread pool has a dynamic number of association piles 320. Each workslot is associated with exactly one association pile. However multiplework slots may share the same association pile. When work is added to awork slot of the thread pool, the calling thread enters the thread gateof the work slot and adds the work to one of the association piles. Allwork added through a particular work slot is directed to the particularassociation pile associated with that work slot. All work related to aparticular key is added through the same work slot and, thus, isdirected to the same association pile.

A thread pool also has a dynamic number of worker threads 330. Eachworker thread is associated with exactly one association pile. Theworker threads poll work form the association piles. But, each workerthread only polls work from the one association pile with which theworker thread is associated. Multiple worker threads can be associatedwith the same association pile and poll work from it. As shown in FIGS.3A and 3B, the number of worker threads and the number of associationpiles in the scalable thread pool can change over time as worker threadsare added or removed according to the methods described with respect toFIGS. 4A, 4B, 5 and 6.

FIG. 3A shows a configuration where the number of worker threads 330 isgreater than the number of work slots 312. When there are more workerthreads than work slots, the number of association piles equals thenumber of work slots. In the configuration of FIG. 3A, there are sevenactive worker threads 330 a, 330 b, 330 c, 330 d, 330 e, 330 f, and 330g. Thus, as shown in FIG. 3A, because there are four work slots 310 a,310 b, 310 c, and 310 d there are also four association piles 320 a, 320b, 320 c, and 320 d. As shown in FIG. 3A, each work slot has a dedicatedassociation pile into which a calling thread which enters the slotplaces work. All work related to a particular key is added through thesame work slot and, thus, is directed to the same dedicated associationpile. There are more worker threads than piles, therefore at least someof the worker threads 330 a, 330 b, 330 c, 330 d, 330 e, 330 f, and 330g need to share some of the association piles. That is to say more thanone worker thread can be removing work from each association pile. Forexample, worker threads 330 a and 330 b both poll work from associationpile 320 a.

FIG. 3B shows a configuration where the number of worker threads 330 isless than the number of work slots 312. Where there are less workerthreads than work slots, the number of association piles equals thenumber of work threads. Thus, FIG. 3B shows three worker threads 330 a,330 b, 330 c and three association piles 320 a, 320 b, and 320 c. Thereare more work slots 310 than association piles 320, so some work slotsmust share piles. For example, the calling threads that enter work slots310 c and 310 d may both place work in association pile 320 c. However,all work related to a particular key is added through the same work slotand, thus, is still directed to the same (shared) association pile. Asshown in FIG. 3B, each worker thread however has a dedicated associationpile from which it removes work. However, if a worker thread has nothingto do, it attempts to pull work from another thread's pile before goingto sleep.

Adding and Removing Threads

The relationship between the worker threads, association piles, andworker threads is taken into consideration when adding worker threadsand/or removing worker threads to the scalable thread pool of FIGS. 3Aand 3B. It is important to maintain a balanced distribution of workerthreads, slots, and association pools. Additionally, it is required toensure that the properties of the thread pool are maintained such thatwhere there are more worker threads than work slots, the number ofassociation piles equals the number of work slots and where there areless worker threads than work slots, the number of association pilesequals the number of work threads. Additionally, thread safety and theFIFO order of elements related to the same key must be preserved duringchanges to worker thread count and/or association pile count. FIGS. 4Aand 4B illustrate methods for adding and removing worker threads to thescalable thread pool of FIGS. 3A and 3B in accordance with theseobjectives.

FIG. 4A shows a method of adding a worker thread to the scalable threadpool of FIGS. 3A and 3B. At step 400, start the process to add a workerthread to the scalable thread pool. At step 402, compare the currentthread count to the work slot count. If the determination is made 404that the worker thread count>=work slot count, such as shown, forexample, in FIG. 3A, proceed to step 406. If the worker threadcount>=work slot count then it must be true that one or more associationpile must be associated with more than one worker thread. At step 406,determine which association pile is shared by the smallest number ofworker threads and select this pile (for example Association Pile 320 din FIG. 3A). At step 408, associate the pile selected in step 406 with anew worker thread. Then proceed to step 430 ending the process foradding a worker thread. This process makes sure the worker thread isadded to the association pile which has the least number of workerthreads.

If the determination is made 414 that the worker thread count<work slotcount, such as shown, for example in FIG. 3B then proceed to step 416.As illustrated in FIG. 3B, if the worker thread count<work slot count,there must be at least two work slots that share the same associationpile. We need to associate one of these slots (e.g. work slot 310 c orwork slot 310 d) with a new association pile and also create a newworker thread for the new association pile. Meanwhile, the oldassociation pile 320 c is still processed by the worker thread 330 cthat was responsible for all tasks coming through both of work slots 310c and 310 d. If we create a new association pile for work slot 310 d weneed to make sure that all tasks that work slot 310 d put in the sharedassociation pile 320 c are completed before the new association pileassociated with work slot 310 d is activated, in order to maintain FIFOordering of tasks.

Referring again to FIG. 4A, at step 416 a slot which is sharing anassociation pile is selected (e.g. Work Slot 310 d of FIG. 3B). At step418 a new association pile is created and associated with the work slotselected in step 416. However, the corresponding daemon is not startedimmediately. Instead at step 420 a synthetic StartWorker job is added tothe to the old shared association pile (e.g. association pile 320 c ofFIG. 3B). By the time the StartWorker job is processed in the old sharedassociation pile, it is guaranteed by first-in-first out ordering thatall previously posted jobs in the old shared association pile formerlyassociated with work slot 310 d slot are processed. Thus, when thesynthetic StartWorker job is processed, at step 422, a new worker threadis started and associated with the new association pile associated withthe work slot selected in step 416. Then proceed to step 430 ending theprocess for adding a worker thread.

FIG. 4B shows a method of removing a worker thread from the scalablethread pool of FIGS. 3A and 3B. At step 450, start the process to removea worker thread from the scalable thread pool. At step 452, compare thecurrent thread count to the work slot count. If the determination ismade 454 that the worker thread count>work slot count, such as shown,for example, in FIG. 3A, proceed to step 456. At step 456 select one ofthe work slots that is served by the largest number of worker threads(e.g. select one of work Slots 310 a, 310 b, or 310 c from FIG. 3A). Atstep 458 add a synthetic StopWorker job to the thread pool via the workslot selected in step 456. Then proceed to step 480 ending the processfor removing a worker thread. When the StopWorker job is polled it willstop whichever thread processes it. Thus reducing the number of workerthreads serving that slot. For example a StopWorker job place in workslot 310 a will be placed in association pile 320 a and the polled byone of worker thread 330 a and 330 b stopping whichever thread polls theStopWorker job from the association pile 320 a.

However, if the determination is made 464 that the worker threadcount<=work slot count, such as shown, for example, in FIG. 4B, proceedto step 466. If the worker thread count<=work slot count, every pile isprocessed by one and only one worker thread. Thus, if a worker thread isto be stopped, an association pile will also have to be removed and theslot(s) associated with the removed association pile redirected. At step466, select an association pile (P1) that is shared by the smallestnumber of work slots (e.g. Association Pile 320 a in FIG. 3B). At step468 add a StopWorker job to the association pile (P1) selected in step466. When the “StopWorker” executes it will: Close all work slots (e.g.work slot 310 a Of FIG. 3B) corresponding to P1 at step 470; find a pile(P2) that is shared with the next smallest number of slots (e.g.association pile 320 b in FIG. 3B) at step 472; and at step 474, mergethe content of P1 (e.g. association pile 320 a in FIG. 3B) into P2 (e.g.association pile 320 b in FIG. 3B) and discard P1 (e.g. Association Pile320 a in FIG. 3B) and redirect all closed slots (e.g. worker slot 310 aof FIG. 3B) to P2 (e.g. association pile 320 b in FIG. 3B) and re-openthe closed slot(s). Then proceed to step 480 ending the process forremoving a worker thread.

Dynamic Thread Pool Resizing

In embodiments the present disclosure describes a system and methodwhich support dynamic thread pool sizing suitable for use inmulti-threaded processing environment such as a distributed data grid.Dynamic thread pool resizing can be performed, for example, in ascalable thread pool associated with a service thread in the distributeddata grid. Dynamic thread pool resizing utilizes measurements of threadpool throughput and worker thread utilization in combination withanalysis of the efficacy of prior thread pool resizing actions todetermine whether to add or remove worker threads from a thread pool ina current resizing action. Furthermore, the dynamic thread pool resizingsystem and method can accelerate or decelerate the resizing analysisand, thus, the rate of worker thread addition and removal depending onthe needs of the system. Optimizations are incorporated to preventsettling on a local maximum throughput. The dynamic thread pool resizingsystem and method thereby provides rapid and responsive adjustment ofthread pool size in response to changes in work load and processoravailability.

In accordance with an embodiment of the invention, the distributed datagrid can dynamically size/resize the scalable thread pools to maximizethe throughput of the pool and minimize the utilization of systemresources. Sizing of the thread pool is achieved by iterativeperformance of a resizing analysis as described below. The abovedescription provides methods for adding threads to and removing threadsfrom the scalable thread pool of FIGS. 3A and 3B. The followingdescription provides methods for determining when to add and removethreads from the scalable thread pool in response to changes in workload and processor availability. The sizing and resizing mechanismsdescribed below may be applied to the scalable thread pool describedabove or to other variable size and/or scalable thread pools.

In a distributed data grid as described above, the workload may changesignificantly from service thread to service thread and over time withrespect to each service thread. Adding complexity is the fact that in adistributed data grid, a number of distributed cache services fordifferent named caches may operate in the same node simultaneously.Furthermore multiple nodes with multiple different service threads mayoperate on the same server therefore sharing the processor resources.The utilization of these various service threads may also change overtime. Thus, in a distributed data grid the optimum size for a threadpool can vary dramatically, based not only on the work presented to theservice thread associated with the thread pool, but also based on whatwork is concurrently being presented to other service threads on thesame server. Thus, it is desirable for a dynamic thread pool resizingmechanism to effect resizing in a way that responds rapidly tofluctuations in workload and can settle upon an optimal thread pool sizefor a particular workload and environment in a short number ofiterations.

FIG. 5 illustrates a system and method for supporting dynamic threadpool sizing in a distributed data grid, in accordance with an embodimentof the invention. As shown in FIG. 5, a thread pool 500, such as ascalable thread pool, can dynamically adjust its thread count. At step501, the system can measure a total throughput of a thread pool 500 fora period. Then, at step 502, the system can determine a change of thetotal throughput of the thread pool 500 from a last period and resizethe thread pool by a random amount, if one or more criteria aresatisfied. Additionally, at step 503, the system can determine a lengthfor a next period based on how effective a resizing of the thread pool500 in the last period was.

This dynamic thread pool resizing method is used in conjunction with thescalable thread pool of FIGS. 3A and 3B to dynamically adjust the threadcount in order to: increase the total throughput of the scalable threadpool and/or minimize the resource utilization of the scalable threadpool. Dynamic resizing is done via a periodic synthetic ResizePool jobinserted into the scalable thread pool described above. In general termsthe synthetic ResizePool job uses a resizing method which analyzes theperformance response to adding or removing threads and uses the resultsof the analysis to determine whether to add or remove more threads andalso to determine how long to wait before reanalyzing performance.Additionally, once a potential maximum throughput has been achieved, thenumber of threads in the thread pool is periodically increased ordecreased by a random amount in an attempt to avoid settling at a localmaximum throughput.

The scheduling of periodic synthetic ResizePool job is based on avariable period between resize jobs. The period of time betweeninserting one ResizePool job and the next ResizePool job is a functionof how effective the last resize was. When executing a ResizePool jobchanges the throughput, the period of time between inserting thatResizePool job and the next ResizePool job is decreased. When executinga ResizePool job does not change the throughput significantly, theperiod of time between inserting that ResizePool job and the nextResizePool job is increased. The method is essentially an iterativeperformance analysis experiment and can adjust the thread pool sizedynamically to take account changes in workload, throughput, andprocessor availability based on measurements of throughput and threadutilization alone.

FIG. 6 shows an illustration of steps performed in the syntheticResizePool job. At step 600 the synthetic ResizePool job starts at theexpiration of the calculated period and is inserted into the scalablethread pool described above for execution. The job is then polled froman association pile by a worker thread and processed as shown. At step602, the job first measures the total throughput of the pool (T.now) andthe change in total throughput (T.delta) since it last ran (T.last).T.delta can be calculated as the difference between T.now and T.last.T.now is stored in memory for use as T.last next time the job is run. Atstep 604, the job determines if it is time to “shake” the pool. Thisdetermination can be made using an iteration counter, or a timer, or theequivalent. If it is time to “shake” the pool, the job performs step 606and resizes the pool by a random amount and then reschedules itself atstep 622. The random amount may be calculated as a random percentage ofthread count within a particular range, or a random percentage of apreconfigured number of threads. The ResizePool job starts again at step600 at the expiration of the calculated period when is inserted againinto the scalable thread pool described above for execution. In analternative embodiment, the ResizePool job is performed by a dedicatedthread and/or a thread not in the thread pool.

Referring again to FIG. 6, if it is not time to “shake” the pool at step604, the job moves on to step 608. At step 608 the job calculates what a“significant” throughput change would be (T.jitter) as a simple function(for example 10% or 5%) of T.last. The job then compares T.delta toT.jitter to see if a significant change in throughput has occurred. Toput it another way at step 608, the job determines whether thedifference between throughput the last time the job was run and thecurrent throughput represents a significant change in throughputrelative to the past throughput. (Alternatively the significance of thechange in throughput could be made by comparison to the currentthroughput instead of the prior throughput).

If there was no significant change in throughput since the job was lastrun, as determined by comparing T.delta to T.jitter at step 608, the jobmoves to step 610. At step 610, the job adds one or more threads to thethread pool if the thread pool is overutilized or removes one or morethreads from the thread pool if the thread pool is underutilized. If thethread pool is neither overutilized nor underutilized the job makes nochange to the thread pool. The thread pool is considered overutilized ifthe number of active worker threads, at the time the Resize.Pool job isrun, is above some fixed percentage of the total worker count (e.g. 66%or 80%). The thread pool is considered underutilized if the number ofactive worker thread is below some fixed percentage of the total workercount (e.g. 33% or 20%). Note that even where a thread pool is “maxedout” i.e. the thread pool cannot perform any additional work, theindicated thread utilization will be less than 100% because a fractionof the worker threads will be “between jobs” at any moment. After addingthreads, removing threads or making no change to the number of threads,the job moves to step 620.

If there was a significant change in throughput since the job was lastrun detected at step 608, the next action taken by the job depends uponwhat action was taken the last time the job was performed (previousresizing action). Thus, the previous resizing action (i.e. addingthreads, removing threads or taking no action) is determined at step612. The previous resizing action is typically recorder in a stateassociated with the Resize.Pool job along with other values such asT.now/T.last and the current duration of the period. These values may bestored for example in memory, such that the Resize.Pool job has accessto them each time it runs.

If threads were added in the previous action, the job moves to step 614.At step 614, if T.delta indicates an increase in throughput, the jobadds one or more additional threads to the thread pool and reduces theperiod of time before the next analysis. At step 614, if T.Deltaindicates a decrease in throughput, the job removes one or more threadsfrom the thread pool and increases the period of time before the nextanalysis. A decrease in throughput in response to adding threads can beindicative that too many threads have been added, e.g. in response toincreasing workload, “overshooting” the optimal number of threads. Thus,one or more threads are removed and analysis is decelerated to dampenoscillations. After adding threads or removing threads the job moves tostep 620.

If threads were removed in the previous action, the job moves to step616. At step 616, if T.delta indicates an increase in throughput, thejob removes one or more further threads from the thread pool and reducesthe period of time before the next analysis. At step 616, if T.deltaindicates a decrease in throughput, the job adds back one or morethreads to the thread pool and increases the period of time before thenext analysis. A decrease in throughput in response to removing threadscan be indicative that too many threads have been removed, e.g. inresponse to diminishing workload, “undershooting” the optimal number ofthreads. Thus, one or more threads are added back and analysis isdecelerated to dampen oscillations. After adding threads or removingthreads the job moves to step 620.

Where the ResizePool job determines that a resizing action should beperformed to add or remove worker threads from the scalable thread pool,the ResizePool job causes addition or removal of worker threads byinserting one or more StartWorker job or StopWorker job into the threadpool as described above with respect to FIGS. 4A and 4B. The number ofthreads added or removed in the steps described above (and consequentlythe number of StartWorker job or StopWorker job which should be insertedinto the thread pool) should be selected so as to be effective for thethread pool in which the job is running. Thus, for a thread pool with alarger thread count, a larger number of threads can be added or removedin each operation. For a thread pool with a smaller thread count, asmaller number of threads can be added or removed in each operation. Thenumber of threads added or removed in a step can in one embodiment bedetermined based on a function of the current thread count, for example5%, 10%, or 20% of the current thread count. In the overshoot andundershoot examples given above a lower number of threads may be addedor removed to correct the overshoot, for example, half the number ofthreads added or removed in the prior operation. Alternatively thenumber of threads added or removed in a thread can be fixed (for exampleone thread at a time).

It should be noted that the rate of thread addition or removal from thethread pool will depend on the number of threads added or removed ineach iteration of the Resize.Pool job and the frequency at whichResize.Pool jobs are performed. Thus, if the period is reduced, thefrequency of Resize.Pool job increases and thus more iterations areperformed in unit time. Thus more additions of removals of workerthreads can also be performed in unit time. This allows the dynamicresizing system and method to respond rapidly to changes in throughput,workload and other factors such as processor availability.

If no change in the number of threads was made in the previous action,the job moves to step 618. At step 618, if T.delta indicates an increasein throughput and the thread pool is overutilized, the job adds one ormore threads to the thread pool. At step 618, if T.delta indicates adecrease in throughput and the thread pool is underutilized, the jobremoves one or more threads from the thread pool. If neither of theabove statements are true, the job makes no change to the thread pool.After adding threads, removing threads or making no change to the numberof threads, the job moves to step 620.

At step 620, if a decision was made in any of the previous steps to addor remove threads, the synthetic “ResizePool” job schedules itself torun again in half of its new period in order to gather new throughputstatistics after the system has had a chance to settle down. Aftergathering new throughput statistics (or directly if no change to thenumber of threads was made), the synthetic “ResizePool” job schedulesitself to run again in its new period which restarts the job again atstep 600 after expiration of the period. Additionally, the resizingaction taken should be stored in memory such that the next iteration ofthe ResizePool job will have access to information indicating thepervious resizing action taken. The ResizePool job will be runrepeatedly and iteratively adjusting the number of worker threads in thethread pool in response to the throughput and thread utilizationmeasures and accelerating or decelerating analysis by increasing ordecreasing the delay period before the next job in response to theefficacy of a prior resizing action as described above.

In embodiments of the present invention, the distributed data grid 100implements one or more scalable thread pool system and method asdescribed above and illustrated in FIGS. 2, 3A, 3B, 4A, and 4B. Inembodiments of the present invention, distributed data grid 100implements one or more system and method for dynamic resizing of ascalable thread pool as described above and illustrated in FIGS. 5 and6. In particular embodiments, the scalable thread pool system and methodand/or the system and method for dynamic resizing of a scalable threadpool may be implemented with respect to one or more service threadoperating on nodes of the distributed data grid 100, including forexample, the cache service thread, and proxy service thread.

FIG. 7 illustrates implementation of a scalable thread pool and a systemfor dynamic resizing of a scalable thread pool in a distributed datagrid, in accordance with an embodiment of the invention. As shown, forexample, in FIG. 7, a service provided by a node 130 a in a distributeddata grid 100 can be provided by a service thread 710. The service maybe, for example, a cache service 132 a. To provide extra processingresources, the service thread 710 may perform work in cooperation with ascalable thread pool 700 comprising a scalable number of worker threads(three shown) 702 a, 702 b, 702 c. In an embodiment, the scalable threadpool 700 implements the scalable thread pool system and method asdescribed above and illustrated in FIGS. 2, 3A, 3B, 4A, and 4B. Thescalable thread pool includes a resizing system 720 for adjusting thenumber of threads in the scalable thread pool 700 based on throughputand thread utilization. In an embodiment, the resizing system 720implements the system and method for dynamic resizing of a scalablethread pool as described above and illustrated in FIGS. 5 and 6.Although service thread 710 of cache service 132 a is shown forillustrative purposes, the scalable thread pool 700 and resizing system720 may also be implemented with respect to a wide variety of otherthreads in distributed data grid 100 where the thread operates incooperation with a thread pool of worker threads.

By providing a scalable thread pool and a system and method for dynamicresizing of the scalable thread pool in response to thread utilizationand throughput, the present disclosure enhances operation of a thread,such as a service thread in the distributed data grid, which utilizesthe scalable thread pool to provide additional resources to the servicethread, thereby improving performance of the distributed data grid andthe ability of the distributed data grid to respond to changing demands.While described with respect to a distributed data grid this scalablethread pool and dynamic resizing system and method described above isalso applicable to a wide variety of situations in which a thread uses athread pool to provide additional resources and needs to scale to copewith variable demand. For example the scalable thread pool and dynamicresizing system and method described above is applicable in a widevariety of multi-threaded processing environments and applications. Thedynamic resizing system and method can also be applied to variablesize/scalable thread pools having a different configuration thanillustrated in FIGS. 2, 3A, 3B, 4A, and 4B.

While various embodiments of the present invention have been describedabove, it should be understood that they have been presented by way ofexample, and not limitation. It will be apparent to persons skilled inthe relevant art that various changes in form and detail can be madetherein without departing from the spirit and scope of the invention.

Many features of the present invention can be performed in, using, orwith the assistance of hardware, software, firmware, or combinationsthereof. The present invention may be conveniently implemented using oneor more conventional general purpose or specialized digital computer,computing device, machine, or microprocessor, including one or moreprocessors, memory and/or computer readable storage media programmedaccording to the teachings of the present disclosure. Features of theinvention may also be implemented in hardware using, for example,hardware components such as application specific integrated circuits(ASICs) and programmable logic device. Implementation of the hardwarestate machine so as to perform the functions described herein will beapparent to persons skilled in the relevant art.

Features of the present invention can be incorporated in software and/orfirmware for controlling the hardware of a processing system, and forenabling a processing system to interact with other mechanisms utilizingthe results of the present invention. Such software or firmware mayinclude, but is not limited to, application code, device drivers,operating systems and execution environments/containers. Appropriatesoftware coding can readily be prepared by skilled programmers based onthe teachings of the present disclosure, as will be apparent to thoseskilled in the software art.

In some embodiments, the present invention includes a computer programproduct which is a storage medium or computer readable medium (media)having instructions stored thereon/in which can be used to program acomputer to perform any of the processes of the present invention. Thestorage medium or computer readable medium can include, but is notlimited to, any type of disk including floppy disks, optical discs, DVD,CD-ROMs, microdrive, and magneto-optical disks, ROMs, RAMs, EPROMs,EEPROMs, DRAMs, VRAMs, flash memory devices, magnetic or optical cards,nanosystems (including molecular memory ICs), or any type of media ordevice suitable for storing instructions and/or data. In embodiments,the storage medium or computer readable medium can be non-transitory.

The foregoing description of the present invention has been provided forthe purposes of illustration and description. It is not intended to beexhaustive or to limit the invention to the precise forms disclosed.Many modifications and variations will be apparent to the practitionerskilled in the art. The embodiments were chosen and described in orderto best explain the principles of the invention and its practicalapplication, thereby enabling others skilled in the art to understandthe invention for various embodiments and with various modificationsthat are suited to the particular use contemplated. It is intended thatthe scope of the invention be defined by the following claims and theirequivalents.

What is claimed is:
 1. A method for supporting dynamic thread poolresizing of a thread pool comprising a plurality of worker threads in amulti-threaded processing system, the method comprising: performing aresizing job; wherein the resizing job comprises measuring a throughput(T.now) of the thread pool in a current period; wherein the resizing jobfurther comprises calculating a change in throughput of the thread pool(T.delta) from T.now and a throughput of the thread pool (T.last)measured in a previous period; wherein the resizing job furthercomprises performing a resizing action which comprises one of causingone or more worker threads to be added the thread pool, causing one ormore worker threads to be removed from the thread pool, and causing nochange to the thread pool; wherein the resizing job further comprisescalculating a duration for the next period based on an efficacy, asindicated by T.delta, of a prior resizing action performed after theprevious period; and wherein the resizing job further comprisesscheduling a next resizing job to be performed after expiration of thenext period.
 2. The method of claim 1, wherein said resizing actioncomprises one of causing addition of a random number of worker threadsto the thread pool and causing removal of a random number of workerthreads from the thread pool if a time period for random resizing hasexpired.
 3. The method of claim 1, wherein said resizing actioncomprises causing addition of one or more worker threads to the threadpool if the prior resizing action also caused addition of one or moreworker threads to the thread pool and T.delta indicates that throughputhas increased significantly in the current period relative to theprevious period.
 4. The method of claim 1, wherein said resizing actioncomprises causing removal of one or more worker threads from the threadpool if the prior resizing action caused addition of one or more workerthreads to the thread pool and T.delta indicates that throughput hasdecreased significantly in the current period relative to the previousperiod.
 5. The method of claim 1, wherein said resizing action comprisescausing removal of one or more worker threads from the thread pool ifthe prior resizing action also caused removal of one or more workerthreads from the thread pool and T.delta indicates that throughput hasincreased significantly in the current period relative to the previousperiod.
 6. The method of claim 1, wherein said resizing action comprisescausing addition of one or more worker threads to the thread pool if theprior resizing action caused removal of one or more worker threads fromthe thread pool and T.delta indicates that throughput has decreasedsignificantly in the current period relative to the previous period. 7.The method of claim 1, wherein said resizing action comprises causingaddition of one or more worker threads to the thread pool if the priorresizing action caused no change to the thread pool, the plurality ofworker threads in the thread pool are overutilized, and T.deltaindicates that throughput has increased significantly in the currentperiod relative to the previous period.
 8. The method of claim 1,wherein said resizing action comprises causing removal of one or moreworker threads from the thread pool if the prior resizing action causedno change to the thread pool, the plurality of worker threads in thethread pool are underutilized, and T.delta indicates that throughput hasdecreased significantly in the current period relative to the previousperiod.
 9. The method of claim 1, wherein said resizing action comprisescausing addition of one or more worker threads to the thread pool ifT.delta indicates that throughput has not changed significantly in thecurrent period relative to the previous period, and the plurality ofworker threads in the thread pool are overutilized.
 10. The method ofclaim 1, wherein said resizing action comprises causing removal of oneor more worker threads from the thread pool if T.delta indicates thatthroughput has not changed significantly in the current period relativeto the previous period, and the plurality of worker threads in thethread pool are underutilized.
 11. A system for supporting dynamicthread pool resizing, the system comprising: a computer system having amemory and a processor, wherein the processor has a plurality of coresand is capable of multi-threaded operation; a thread pool operating onsaid computer system, wherein said thread pool comprises a plurality ofworker threads; wherein a worker thread of said plurality of workerthreads is configured to perform a resizing job comprising, measuring athroughput (T.now) of the thread pool in a current period, calculating achange in throughput of the thread pool (T.delta) from T.now and athroughput of the thread pool (T.last) measured in a previous period,performing a resizing action wherein the resizing action comprises oneof causing one or more worker threads to be added the thread pool,causing one or more worker threads to be removed from the thread pool,causing no change to the thread pool, calculating a duration for thenext period based on an efficacy, as indicated by T.delta, of a priorresizing action performed after the previous period, and scheduling anext resizing job to be performed by a worker thread of said pluralityof worker threads after expiration of the next period.
 12. The system ofclaim 11, wherein said resizing action comprises one of causing additionof a random number of worker threads to the thread pool and causingremoval of a random number of worker threads from the thread pool if atime period for random resizing has expired.
 13. The system of claim 11,wherein said resizing action comprises causing addition of one or moreworker threads to the thread pool if the prior resizing action alsocaused addition of one or more worker threads to the thread pool andT.delta indicates that throughput has increased significantly in thecurrent period relative to the previous period.
 14. The system of claim11, wherein said resizing action comprises causing removal of one ormore worker threads from the thread pool if the prior resizing actioncaused addition of one or more worker threads to the thread pool andT.delta indicates that throughput has decreased significantly in thecurrent period relative to the previous period.
 15. The system of claim11, wherein said resizing action comprises causing removal of one ormore worker threads from the thread pool if the prior resizing actionalso caused removal of one or more worker threads from the thread pooland T.delta indicates that throughput has increased significantly in thecurrent period relative to the previous period.
 16. The system of claim11, wherein said resizing action comprises causing addition of one ormore worker threads to the thread pool if the prior resizing actioncaused removal of one or more worker threads from the thread pool andT.delta indicates that throughput has decreased significantly in thecurrent period relative to the previous period.
 17. The system of claim11, wherein said resizing action comprises causing addition of one ormore worker threads to the thread pool if the prior resizing actioncaused no change to the thread pool, the plurality of worker threads inthe thread pool are overutilized, and T.delta indicates that throughputhas increased significantly in the current period relative to theprevious period.
 18. The system of claim 11, wherein said resizingaction comprises causing removal of one or more worker threads from thethread pool if the prior resizing action caused no change to the threadpool, the plurality of worker threads in the thread pool areunderutilized, and T.delta indicates that throughput has decreasedsignificantly in the current period relative to the previous period. 19.The system of claim 1, wherein said resizing action comprises: causingaddition of one or more worker threads to the thread pool if T.deltaindicates that throughput has not changed significantly in the currentperiod relative to the previous period, and the plurality of workerthreads in the thread pool are overutilized; and causing removal of oneor more worker threads from the thread pool if T.delta indicates thatthroughput has not changed significantly in the current period relativeto the previous period, and the plurality of worker threads in thethread pool are underutilized.
 20. A non-transitory computer readablemedium comprising instructions stored thereon for supporting dynamicthread pool resizing of a thread pool comprising a plurality of workerthreads in a multi-threaded processing system, which instructions whenexecuted by a worker thread in said thread pool cause the worker threadto perform steps comprising: performing a resizing job; wherein theresizing job comprises measuring a throughput (T.now) of the thread poolin a current period; wherein the resizing job further comprisescalculating a change in throughput the thread pool (T.delta) from T.nowand a throughput of the thread pool (T.last) measured in a previousperiod; wherein the resizing job further comprises performing a resizingaction which comprises one of causing one or more worker threads to beadded the thread pool, causing one or more worker threads to be removedfrom the thread pool, and causing no change to the thread pool; whereinthe resizing job further comprises calculating a duration for the nextperiod based on an efficacy, as indicated by T.delta, of a priorresizing action performed after the previous period; and wherein theresizing job further comprises scheduling a next resizing job to beperformed after expiration of the next period.